package com.lei.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @ClassName DataSourceConfiguration
 * @Description TODO
 * @Author Admin
 * @Date 2021/8/4 15:13
 * @Version 1.0
 */
//@PropertySource("jdbc.properrties")
public class DataSourceConfiguration {
    @Value("com.mysql.jdbc.Driver")
    private String driver;
    @Value("jdbc:mysql://localhost:3306/mysql")
    private String url;
    @Value("root")
    private String username;
    @Value("admin")
    private String password;
    @Bean("dataSource")
    public DataSource getDataSource() throws PropertyVetoException {
        ComboPooledDataSource source = new ComboPooledDataSource();
        source.setDriverClass(driver);
        source.setJdbcUrl(url);
        source.setUser(username);
        source.setPassword(password);
        return source;

    }

}
